/*============================================================================
 *
 * ucl_aes_gcm.h [22-sep-12]
 *
 *==========================================================================*/
/*============================================================================
 *
 * Copyright (c) 2012 Maxim Integrated. All Rights Reserved. Do not disclose.
 *
 * This software is the confidential and proprietary information of
 * Maxim Integrated ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Maxim Integrated.
 *
 * Maxim Integrated makes no representations or warranties about the suitability of
 * the software, either express or implied, including but not limited to
 * the implied warranties of merchantability, fitness for a particular purpose,
 * or non-infrigement. Maxim Integrated shall not be liable for any damages suffered
 * by licensee as the result of using, modifying or distributing this software
 * or its derivatives.
 *
 *==========================================================================*/
/*============================================================================
 *
 * Purpose : AES-GCM and AES-GMAC API description
 *
 *==========================================================================*/
/** @file ucl_aes_gcm.h
 * @defgroup UCL_GCM_AES AES GCM
 * Encrypt / Decrypt with AES in GCM (Galois Counter Mode)
 * provide authentication with GMAC (Galois MAC).
 *
 * @par Header:
 * @link ucl_aes_gcm.h ucl_aes_gcm.h @endlink
 *
 * @ingroup UCL_GCM
 */
/** <b>AES-GCM</b>.
 * GCM and GMAC internal table initialization.
 *
 * @ingroup UCL_GCM_AES
 */

void ucl_gcm_init_r(void);
/** <b>AES-GCM</b>.
 * GCM and GMAC internal table precomputation
 * used for platforms with RAM memory large enough (requires 4KB free space)
 * this precomputation provides better performances
 *
 * @param[in]  h: u8 array; h is the encryption of the 16-byte null block  0...0
 *
 * @ingroup UCL_GCM_AES
 */
#ifdef LARGE_MEMORY
void ucl_gcm_init_prod(u8 *h);
#endif

/** <b>AES-GCM</b>.
 * computes the GCM data (crypto+tag) from plaintext and authenticated add. data
 * @param[out]  auth_tag: result, u8 array representing the tag
 * @param[in]   auth_tag_bit_len: number of bits of the result tag; values between 64 and 128
 * @param[out]  c: the result u8 array representing the output (crypto in encryption, plain in decryption); its size is the same than the plaintext one
 * @param[in] p: the input u8 array representing the input (plain in encryption, crypto in decryption);
 * @param[in] input_bit_length_high, input_bit_len_low: two words representing the bit size of the input;the  maximum value is 2^39-256
 *  @param[in] aad: the input u8 array representing the add.authenticated data
 *  @param[in] aad_bit_length_high, aad_bit_len_low: two words representing the bit size of the AAD; the maximum value is 2^64
 *  @param[in] key: the u8 array representing the AES key
 *  @param[in] iv: the input u8 array representing the IV
 *  @param[in] iv_bit_length_high, iv_bit_len_low: two words representing the bit size of the IV;
the maximum value is 2^64
 *  @param[in] mode: UCL_CIPHER_ENCRYPT or UCL_CIPHER_DECRYPT; determines if p is encrypted or decrypted
 *  @return Error code
 *
 * @retval #UCL_OK             no error occurred
 * @retval #UCL_INVALID_INPUT  one of the input is the pointer NULL
 * @retval #UCL_INVALID_OUTPUT one of the output is the pointer NULL
 *
 * @ingroup UCL_GCM_AES

 */
int ucl_aes_gcm_auth(u8 *auth_tag,int auth_tag_bit_len,u8 *c,u8 *p,int input_bit_len_high,int input_bit_len_low,u8 *aad, int aad_bit_len_high,int aad_bit_len_low, u8 *key,u8 *iv,int iv_bit_len_high, int iv_bit_len_low,int mode);
/** <b>AES-GMAC</b>.
 * computes the GMAC data (tag) from authenticated add. data
 * @param[out]  auth_tag: result, u8 array representing the tag
 * @param[in]   auth_tag_bit_len: number of bits of the result tag; values between 64 and 128
 * @param[in] aad: the input u8 array representing the add.authenticated data
 * @param[in] aad_bit_length_high, aad_bit_len_low: two words representing the bit size of the AAD; the maximum value is 2^64
 * @param[in] key: the u8 array representing the AES key
 * @param[in] iv: the input u8 array representing the IV
 * @param[in] iv_bit_length_high, iv_bit_len_low: two words representing the bit size of the IV;
the maximum value is 2^64
 * @param[in] mode: UCL_CIPHER_ENCRYPT or UCL_CIPHER_DECRYPT; determines if p is encrypted or decrypted
 * @return Error code
 *
 * @retval #UCL_OK             no error occurred
 * @retval #UCL_INVALID_INPUT  one of the input is the pointer NULL
 * @retval #UCL_INVALID_OUTPUT one of the output is the pointer NULL
 *
 * @ingroup UCL_GCM_AES

 */
int ucl_aes_gmac_auth(u8 *auth_tag,int auth_tag_bit_len,u8 *aad, int aad_bit_len_high,int aad_bit_len_low, u8 *key,u8 *iv,int iv_bit_len_high, int iv_bit_len_low);
